package com.tsingteng.cosfun.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutCompat;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tsingteng.cosfun.R;

import org.w3c.dom.Text;

/**
 * 描述 :
 * 创建人: 肖利.
 * 时间:2018/8/6
 * qq(872179966)
 */

public class DraftsHeaderView extends FrameLayout implements View.OnClickListener {

  private LinearLayout mLlWorks;
  private LinearLayout mLlPlay;
  private TextView mTvWorkNum;
  private TextView mTvWorkLine;
  private TextView mTvPlayNum;
  private TextView mTvPlayLine;
    private OnDraftsHeaderClickListener onDraftsHeaderClickListener;
    private Context context;

    public DraftsHeaderView(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public DraftsHeaderView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public DraftsHeaderView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        this.context = context;
        View view = LayoutInflater.from(context).inflate(R.layout.view_drafts_header, null);
        LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LinearLayoutCompat.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(layoutParams);
        mLlWorks = view.findViewById(R.id.ll_works);
        mLlPlay = view.findViewById(R.id.ll_play);
        mTvWorkNum = view.findViewById(R.id.tv_work_num);
        mTvWorkLine = view.findViewById(R.id.tv_work_line);
        mTvPlayNum = view.findViewById(R.id.tv_play_num);
        mTvPlayLine = view.findViewById(R.id.tv_play_line);
        mTvWorkLine.setVisibility(VISIBLE);
        mTvPlayLine.setVisibility(GONE);
        mLlWorks.setOnClickListener(this);
        mLlPlay.setOnClickListener(this);
        addView(view);
        changUI(true);

    }

    @Override
    public void onClick(View v) {
        if (onDraftsHeaderClickListener==null) return;
        switch (v.getId()) {
            case R.id.ll_works:
                onDraftsHeaderClickListener.onWorkClick();
                changUI(true);
                break;
            case R.id.ll_play:
                onDraftsHeaderClickListener.onPlayClick();
                changUI(false);
                break;
        }
    }

    public void changUI(boolean isWork) {
        if (isWork) {
            mTvWorkLine.setVisibility(VISIBLE);
            mTvPlayLine.setVisibility(GONE);
        }else {
            mTvWorkLine.setVisibility(GONE);
            mTvPlayLine.setVisibility(VISIBLE);
        }
    }

    public interface OnDraftsHeaderClickListener{
        void onWorkClick();
        void onPlayClick();

    }

    public void setOnDraftsHeaderClickListener(OnDraftsHeaderClickListener onDraftsHeaderClickListener) {
        this.onDraftsHeaderClickListener = onDraftsHeaderClickListener;
    }

    public void setIvWorkText(String workText) {
        if (TextUtils.isEmpty(workText)) return;
        mTvWorkNum.setText(workText);

    }

    public void setPlayText(String playText) {
        if (TextUtils.isEmpty(playText)) return;
        mTvPlayNum.setText(playText);
    }

}
